/*
 * @(#)GenericAddress.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.framework.bean;

import java.io.UnsupportedEncodingException;

import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
  GenericAddress.java
  
  <p>
  This class is the GenericAddress. It is to override the 
  javax.mail.internet.InternetAddress to avoid the validation on the email
  address. It can be used for Lotus Notes mail address storage.
  </p>

    @author           Rollo Chan
    @company          DCIVision Limited
    @creation date    03/06/2005
    @version          $Revision: 1.2.2.1 $
 */

public class GenericAddress extends InternetAddress {
  
  private static final Log log = LogFactory.getLog(GenericAddress.class);
  
  public GenericAddress(String address) throws AddressException {
    this(address, false);
  }

  public GenericAddress(String address, boolean strict) throws AddressException {
    InternetAddress[] addresses = InternetAddress.parse(address, false);
    if (addresses.length != 1) {
      this.address = address;
    } else {
      this.address = addresses[0].getAddress();
      this.personal = addresses[0].getPersonal();
      try {
        this.setPersonal(this.personal);
      } catch (Exception e) {
        log.error(e, e);
      }
    }
  }

  public GenericAddress(String address, String personal) throws UnsupportedEncodingException {
    this(address, personal, null);
  }

  public GenericAddress(String address, String personal, String charset) throws UnsupportedEncodingException {
    this.address = address;
    this.setPersonal(personal, charset);
  }

}